/**
 * 
 */
package com.manthano.applogin.authorization.handlers;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutHandler;

import com.manthano.applogin.management.util.PropertyConfigUtil;

/**
 * @author Dell
 */
public class UserAuthenticationLogoutHandler implements LogoutHandler
{
	@Override
	public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
	{
		request.getSession().invalidate();
		SecurityContextHolder.getContext().setAuthentication(null);
		SecurityContextHolder.clearContext();
		try
		{
			Properties properties = PropertyConfigUtil.getLoginProperties();
			response.sendRedirect(request.getRequestURI() + properties.getProperty("LOGOUT_URL"));
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
}
